package ru.demo.abstarctservice.adapter.mapper;

import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.mapstruct.Mapper;
import ru.demo.abstarctservice.entity.BaseEntity;
import ru.demo.abstarctservice.entity.Person;

import java.util.UUID;

@Mapper(componentModel = "spring")
public class UtilsMapper {

    @PersistenceContext
    EntityManager entityManager;

    public <T extends BaseEntity> UUID map(T value) {
        if (value == null) {
            return null;
        }
        return value.getId();
    }

    public Person map(UUID value) {
        if (value == null) {
            return null;
        }
        return entityManager.getReference(Person.class, value);
    }

}